package com.zerox.service.impl;

import com.zerox.mapper.SysUserMapper;
import com.zerox.pojo.SysUser;
import com.zerox.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser login(String username, String password) {
        SysUser sysUser = sysUserMapper.selectByUsername(username);

        //有账户，比较密码
        if (password.equals(sysUser.getPassword())) {
            //密码正确
            return sysUser;
        }
        return null;
    }

    @Override
    public List<SysUser> list(Integer pageNos, Integer pageSize, String realName, Integer roleId) {
        Integer startIndex = (pageNos - 1) * pageSize;
        return sysUserMapper.list(startIndex, pageSize, realName, roleId);
    }

    @Override
    public int count(String realName, Integer roleId) {
        return sysUserMapper.count(realName, roleId);
    }

    @Override
    public int add(SysUser sysUser) {
        return sysUserMapper.add(sysUser);
    }

    @Override
    public SysUser selectById(Integer id) {
        return sysUserMapper.selectById(id);
    }

    @Override
    public int delete(Integer id) {
        return sysUserMapper.delete(id);
    }

    @Override
    public int update(SysUser sysUser) {
        return sysUserMapper.update(sysUser);
    }

    @Override
    public SysUser selectByAccount(String account) {
        return sysUserMapper.selectByUsername(account);
    }

    @Override
    public SysUser selectUserId(Integer id) {
        return sysUserMapper.selectUserId(id);
    }
}
